package com.lxk.controller;

import com.lxk.service.TextService;
import com.lxk.vo.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author JohnSoybean
 * @create 2020/4/8 12:05
 * @description
 */
@Controller
public class TextController {

    @Autowired
    private TextService ts;

    /**
     * 展示积分规则
     * @return
     */
    @GetMapping("/rulePoint")
    public String showRulePoint(Model model){
        String ruleText = ts.showRuleText(1);
        model.addAttribute("data", ruleText);
        return "rulePoint";
    }

    /**
     * 展示返利规则
     * @return
     */
    @GetMapping("/ruleRebate")
    public String showRuleRebate(Model model){
        String ruleText = ts.showRuleText(2);
        model.addAttribute("data", ruleText);
        return "ruleRebate";
    }

    /**
     * 展示积分规则
     * @return
     */
    @GetMapping("/ruleVip")
    public String showRuleVip(Model model){
        String ruleText = ts.showRuleText(3);
        model.addAttribute("data", ruleText);
        return "ruleVip";
    }

    /**
     * 展示关于我们文本
     * @return
     */
    @GetMapping("/aboutUs")
    public String showAboutUs(Model model){
        String aboutUsContent = ts.showAboutUs();
        model.addAttribute("data", aboutUsContent);
        return "aboutUs";
    }

    /**
     * 修改规则文本
     * @param ruleInfoId 1积分 2返利 3会员
     * @param ruleInfoText
     * @return
     */
    @PostMapping("/rule/edit")
    @ResponseBody
    public Result<Integer> editRuleText(Integer ruleInfoId, String ruleInfoText){
        ts.editRuleText(ruleInfoId, ruleInfoText);
        return Result.success(1);
    }

    /**
     * 修改关于我们文本
     * @return
     */
    @PostMapping("/aboutUs/edit")
    @ResponseBody
    public Result<Integer> editAboutUsText(String aboutUsContent){
        ts.editAboutUs(aboutUsContent);
        return Result.success(1);
    }

}
